<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Distribution Construction Examples</title>
<link rel="stylesheet" href="../../../math.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../../index.html" title="Math Toolkit 3.3.0">
<link rel="up" href="../weg.html" title="Worked Examples">
<link rel="prev" href="../weg.html" title="Worked Examples">
<link rel="next" href="st_eg.html" title="Student's t Distribution Examples">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../weg.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../weg.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="st_eg.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="section">
<div class="titlepage"><div><div><h4 class="title">
<a name="math_toolkit.stat_tut.weg.dist_construct_eg"></a><a class="link" href="dist_construct_eg.html" title="Distribution Construction Examples">Distribution
        Construction Examples</a>
</h4></div></div></div>
<p>
          The structure of distributions is rather different from some other statistical
          libraries, for example, those written in less object-oriented language
          like FORTRAN and C that provide a few arguments to each free function.
        </p>
<p>
          Boost.Math library instead provides each distribution as a template C++
          class. A distribution is constructed with a few arguments, and then member
          and non-member functions are used to find values of the distribution, often
          a function of a random variate.
        </p>
<p>
          For this demonstration, first we need some includes to access the negative
          binomial distribution (and the binomial, beta and gamma distributions too).
        </p>
<p>
          To demonstrate the use with a high precision User-defined floating-point
          type <code class="computeroutput"><span class="identifier">cpp_bin_float</span></code>, we
          also need an include from Boost.Multiprecision. (We could equally well
          have used a <code class="computeroutput"><span class="identifier">cpp_dec_float</span></code>
          multiprecision type).
        </p>
<p>
          We choose a typedef <code class="computeroutput"><span class="identifier">cpp_bin_float_50</span></code>
          to provide a 50 decimal digit type, but we could equally have chosen at
          128-bit type <code class="computeroutput"><span class="identifier">cpp_bin_float_quad</span></code>,
          or on some platforms <code class="computeroutput"><span class="identifier">__float128</span></code>,
          providing about 35 decimal digits.
        </p>
<pre class="programlisting"><span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">negative_binomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for negative_binomial_distribution</span>
  <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">negative_binomial_distribution</span><span class="special">;</span> <span class="comment">// default type is double.</span>
  <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">negative_binomial</span><span class="special">;</span> <span class="comment">// typedef provides default type is double.</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">binomial</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for binomial_distribution.</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">beta</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for beta_distribution.</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">gamma</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for gamma_distribution.</span>
<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">math</span><span class="special">/</span><span class="identifier">distributions</span><span class="special">/</span><span class="identifier">normal</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for normal_distribution.</span>

<span class="preprocessor">#include</span> <span class="special">&lt;</span><span class="identifier">boost</span><span class="special">/</span><span class="identifier">multiprecision</span><span class="special">/</span><span class="identifier">cpp_bin_float</span><span class="special">.</span><span class="identifier">hpp</span><span class="special">&gt;</span> <span class="comment">// for cpp_bin_float_50</span>
</pre>
<p>
          Several examples of constructing distributions follow:
        </p>
<p>
          First, a negative binomial distribution with 8 successes and a success
          fraction 0.25, 25% or 1 in 4, is constructed like this:
        </p>
<pre class="programlisting"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">mydist0</span><span class="special">(</span><span class="number">8.</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>
</pre>
<p>
          But this is inconveniently long, so we might be tempted to write
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">;</span>
</pre>
<p>
          but this might risk ambiguity with names in <code class="computeroutput"><span class="identifier">std</span>
          <span class="identifier">random</span></code> so <span class="bold"><strong>much</strong></span>
          better is explicit <code class="computeroutput"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span></code>
          statements, for example:
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">negative_binomial_distribution</span><span class="special">;</span>
</pre>
<p>
          and we can still reduce typing.
        </p>
<p>
          Since the vast majority of applications use will be using <code class="computeroutput"><span class="keyword">double</span></code> precision, the template argument
          to the distribution (<code class="computeroutput"><span class="identifier">RealType</span></code>)
          defaults to type <code class="computeroutput"><span class="keyword">double</span></code>, so
          we can also write:
        </p>
<pre class="programlisting"><span class="identifier">negative_binomial_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mydist9</span><span class="special">(</span><span class="number">8.</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span> <span class="comment">// Uses default `RealType = double`.</span>
</pre>
<p>
          But the name <code class="computeroutput"><span class="identifier">negative_binomial_distribution</span></code>
          is still inconveniently long, so, for most distributions, a convenience
          <code class="computeroutput"><span class="keyword">typedef</span></code> is provided, for example:
        </p>
<pre class="programlisting"><span class="keyword">typedef</span> <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">negative_binomial</span><span class="special">;</span> <span class="comment">// Reserved name of type double.</span>
</pre>
<div class="caution"><table border="0" summary="Caution">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Caution]" src="../../../../../../../doc/src/images/caution.png"></td>
<th align="left">Caution</th>
</tr>
<tr><td align="left" valign="top"><p>
            This convenience typedef is <span class="bold"><strong>not provided</strong></span>
            if a clash would occur with the name of a function; currently only <code class="computeroutput"><span class="identifier">beta</span></code> and <code class="computeroutput"><span class="identifier">gamma</span></code>
            fall into this category.
          </p></td></tr>
</table></div>
<p>
          So, after a using statement,
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">negative_binomial</span><span class="special">;</span>
</pre>
<p>
          we have a convenient typedef to <code class="computeroutput"><span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span></code>:
        </p>
<pre class="programlisting"><span class="identifier">negative_binomial</span> <span class="identifier">mydist</span><span class="special">(</span><span class="number">8.</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>
</pre>
<p>
          Some more examples using the convenience typedef:
        </p>
<pre class="programlisting"><span class="identifier">negative_binomial</span> <span class="identifier">mydist10</span><span class="special">(</span><span class="number">5.</span><span class="special">,</span> <span class="number">0.4</span><span class="special">);</span> <span class="comment">// Both arguments double.</span>
</pre>
<p>
          And automatic conversion of arguments takes place, so you can use integers
          and floats:
        </p>
<pre class="programlisting"><span class="identifier">negative_binomial</span> <span class="identifier">mydist11</span><span class="special">(</span><span class="number">5</span><span class="special">,</span> <span class="number">0.4</span><span class="special">);</span> <span class="comment">// Using provided typedef of type double, and int and double arguments.</span>
</pre>
<p>
          This is probably the most common usage. Other combination are possible
          too:
        </p>
<pre class="programlisting"><span class="identifier">negative_binomial</span> <span class="identifier">mydist12</span><span class="special">(</span><span class="number">5.</span><span class="special">,</span> <span class="number">0.4F</span><span class="special">);</span> <span class="comment">// Double and float arguments.</span>
<span class="identifier">negative_binomial</span> <span class="identifier">mydist13</span><span class="special">(</span><span class="number">5</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span> <span class="comment">// Both arguments integer.</span>
</pre>
<p>
          Similarly for most other distributions like the binomial.
        </p>
<pre class="programlisting"><span class="identifier">binomial</span> <span class="identifier">mybinomial</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">0.5</span><span class="special">);</span> <span class="comment">// is more concise than</span>
<span class="identifier">binomial_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mybinomd1</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">0.5</span><span class="special">);</span>
</pre>
<p>
          For cases when the typdef distribution name would clash with a math special
          function (currently only beta and gamma) the typedef is deliberately not
          provided, and the longer version of the name must be used, so for example,
          do not use:
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">beta</span><span class="special">;</span>
<span class="identifier">beta</span> <span class="identifier">mybetad0</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">0.5</span><span class="special">);</span> <span class="comment">// Error beta is a math FUNCTION!</span>
</pre>
<p>
          Which produces the error messages:
        </p>
<pre class="programlisting">error C2146: syntax error : missing ';' before identifier 'mybetad0'
warning C4551: function call missing argument list
error C3861: 'mybetad0': identifier not found
</pre>
<p>
          Instead you should use:
        </p>
<pre class="programlisting"><span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">beta_distribution</span><span class="special">;</span>
<span class="identifier">beta_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mybetad1</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">0.5</span><span class="special">);</span>
</pre>
<p>
          or for the gamma distribution:
        </p>
<pre class="programlisting"><span class="identifier">gamma_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mygammad1</span><span class="special">(</span><span class="number">1</span><span class="special">,</span> <span class="number">0.5</span><span class="special">);</span>
</pre>
<p>
          We can, of course, still provide the type explicitly thus:
        </p>
<pre class="programlisting"><span class="comment">// Explicit double precision:  both arguments are double:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span>        <span class="identifier">mydist1</span><span class="special">(</span><span class="number">8.</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>

<span class="comment">// Explicit float precision, double arguments are truncated to float:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;</span>         <span class="identifier">mydist2</span><span class="special">(</span><span class="number">8.</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>

<span class="comment">// Explicit float precision, integer &amp; double arguments converted to float:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;</span>         <span class="identifier">mydist3</span><span class="special">(</span><span class="number">8</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>

<span class="comment">// Explicit float precision, float arguments, so no conversion:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;</span>         <span class="identifier">mydist4</span><span class="special">(</span><span class="number">8.F</span><span class="special">,</span> <span class="number">0.25F</span><span class="special">);</span>

<span class="comment">// Explicit float precision, integer arguments promoted to float.</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">float</span><span class="special">&gt;</span>         <span class="identifier">mydist5</span><span class="special">(</span><span class="number">8</span><span class="special">,</span> <span class="number">1</span><span class="special">);</span>

<span class="comment">// Explicit double precision:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span>        <span class="identifier">mydist6</span><span class="special">(</span><span class="number">5.</span><span class="special">,</span> <span class="number">0.4</span><span class="special">);</span>

<span class="comment">// Explicit long double precision:</span>
<span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="keyword">long</span> <span class="keyword">double</span><span class="special">&gt;</span>   <span class="identifier">mydist7</span><span class="special">(</span><span class="number">8.</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>
</pre>
<p>
          And you can use your own template RealType, for example, <code class="computeroutput"><span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">cpp_bin_float_50</span></code> (an arbitrary 50 decimal
          digits precision type), then we can write:
        </p>
<pre class="programlisting"> <span class="keyword">using</span> <span class="keyword">namespace</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">multiprecision</span><span class="special">;</span>
 <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_50</span><span class="special">&gt;</span>  <span class="identifier">mydist8</span><span class="special">(</span><span class="number">8</span><span class="special">,</span> <span class="number">0.25</span><span class="special">);</span>

 <span class="comment">// `integer` arguments are promoted to your RealType exactly, but</span>
 <span class="comment">// `double` argument are converted to RealType,</span>
 <span class="comment">// most likely losing precision!</span>

 <span class="comment">// So DON'T be tempted to write the 'obvious':</span>
 <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_50</span><span class="special">&gt;</span>  <span class="identifier">mydist20</span><span class="special">(</span><span class="number">8</span><span class="special">,</span> <span class="number">0.23456789012345678901234567890</span><span class="special">);</span>
<span class="comment">// to avoid truncation of second parameter to `0.2345678901234567` and loss of precision.</span>

<span class="comment">// Instead pass a quoted decimal digit string:</span>
 <span class="identifier">negative_binomial_distribution</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_50</span><span class="special">&gt;</span>  <span class="identifier">mydist21</span><span class="special">(</span><span class="number">8</span><span class="special">,</span> <span class="identifier">cpp_bin_float_50</span><span class="special">(</span><span class="string">"0.23456789012345678901234567890"</span><span class="special">)</span> <span class="special">);</span>

 <span class="comment">// Ensure that all potentially significant digits are shown.</span>
 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span><span class="special">.</span><span class="identifier">precision</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">numeric_limits</span><span class="special">&lt;</span><span class="identifier">cpp_bin_float_50</span><span class="special">&gt;::</span><span class="identifier">digits10</span><span class="special">);</span>
 <span class="comment">// </span>
 <span class="identifier">cpp_bin_float_50</span> <span class="identifier">x</span><span class="special">(</span><span class="string">"1.23456789012345678901234567890"</span><span class="special">);</span>
 <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">mydist8</span><span class="special">,</span> <span class="identifier">x</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
</pre>
<pre class="programlisting"><span class="identifier">showing</span>  <span class="number">0.00012630010495970320103876754721976419438231705359935</span>
            <span class="number">0.00012630010495970320103876754721976419438231528547467</span>
</pre>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>
            When using multiprecision, it is all too easy to get accidental truncation!
          </p></td></tr>
</table></div>
<p>
          For example, if you write
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">mydist8</span><span class="special">,</span> <span class="number">1.23456789012345678901234567890</span><span class="special">)</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
</pre>
<p>
          showing 0.00012630010495970318465064569310967179576805651692929, which
          is wrong at about the 17th decimal digit!
        </p>
<p>
          This is because the value provided is truncated to a <code class="computeroutput"><span class="keyword">double</span></code>,
          effectively <code class="computeroutput"><span class="keyword">double</span> <span class="identifier">x</span>
          <span class="special">=</span> <span class="number">1.23456789012345678901234567890</span><span class="special">;</span></code>
        </p>
<p>
          Then the now <code class="computeroutput"><span class="keyword">double</span> <span class="identifier">x</span></code>
          is passed to function <code class="computeroutput"><span class="identifier">pdf</span></code>,
          and this truncated <code class="computeroutput"><span class="keyword">double</span></code>
          value is finally promoted to <code class="computeroutput"><span class="identifier">cpp_bin_float_50</span></code>.
        </p>
<p>
          Another way of quietly getting the wrong answer is to write:
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">mydist8</span><span class="special">,</span> <span class="identifier">cpp_bin_float_50</span><span class="special">(</span><span class="number">1.23456789012345678901234567890</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
</pre>
<p>
          A correct way from a multi-digit string value is
        </p>
<pre class="programlisting"><span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">pdf</span><span class="special">(</span><span class="identifier">mydist8</span><span class="special">,</span> <span class="identifier">cpp_bin_float_50</span><span class="special">(</span><span class="string">"1.23456789012345678901234567890"</span><span class="special">))</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
</pre>
<div class="tip"><table border="0" summary="Tip">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../../../../../doc/src/images/tip.png"></td>
<th align="left">Tip</th>
</tr>
<tr><td align="left" valign="top"><p>
            Getting about 17 decimal digits followed by many zeros is often a sign
            of accidental truncation.
          </p></td></tr>
</table></div>
<h5>
<a name="math_toolkit.stat_tut.weg.dist_construct_eg.h0"></a>
          <span class="phrase"><a name="math_toolkit.stat_tut.weg.dist_construct_eg.default_arguments_to_distributio"></a></span><a class="link" href="dist_construct_eg.html#math_toolkit.stat_tut.weg.dist_construct_eg.default_arguments_to_distributio">Default
          arguments to distribution constructors.</a>
        </h5>
<p>
          Note that default constructor arguments are only provided for some distributions.
          So if you wrongly assume a default argument, you will get an error message,
          for example:
        </p>
<pre class="programlisting"><span class="identifier">negative_binomial_distribution</span><span class="special">&lt;&gt;</span> <span class="identifier">mydist8</span><span class="special">;</span>
</pre>
<pre class="programlisting">error C2512 no appropriate default constructor available.</pre>
<p>
          No default constructors are provided for the <code class="computeroutput"><span class="identifier">negative</span>
          <span class="identifier">binomial</span></code> distribution, because
          it is difficult to chose any sensible default values for this distribution.
        </p>
<p>
          For other distributions, like the normal distribution, it is obviously
          very useful to provide 'standard' defaults for the mean (zero) and standard
          deviation (unity) thus:
        </p>
<pre class="programlisting"><span class="identifier">normal_distribution</span><span class="special">(</span><span class="identifier">RealType</span> <span class="identifier">mean</span> <span class="special">=</span> <span class="number">0</span><span class="special">,</span> <span class="identifier">RealType</span> <span class="identifier">sd</span> <span class="special">=</span> <span class="number">1</span><span class="special">);</span>
</pre>
<p>
          So in this case we can more tersely write:
        </p>
<pre class="programlisting">  <span class="keyword">using</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">math</span><span class="special">::</span><span class="identifier">normal</span><span class="special">;</span>

  <span class="identifier">normal</span> <span class="identifier">norm1</span><span class="special">;</span>       <span class="comment">// Standard normal distribution N[0,1].</span>
  <span class="identifier">normal</span> <span class="identifier">norm2</span><span class="special">(</span><span class="number">2</span><span class="special">);</span>    <span class="comment">// Mean = 2, std deviation = 1.</span>
  <span class="identifier">normal</span> <span class="identifier">norm3</span><span class="special">(</span><span class="number">2</span><span class="special">,</span> <span class="number">3</span><span class="special">);</span> <span class="comment">// Mean = 2, std deviation = 3.</span>

  <span class="special">}</span>
  <span class="keyword">catch</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">exception</span> <span class="special">&amp;</span><span class="identifier">ex</span><span class="special">)</span>
  <span class="special">{</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">cout</span> <span class="special">&lt;&lt;</span> <span class="identifier">ex</span><span class="special">.</span><span class="identifier">what</span><span class="special">()</span> <span class="special">&lt;&lt;</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">endl</span><span class="special">;</span>
  <span class="special">}</span>

  <span class="keyword">return</span> <span class="number">0</span><span class="special">;</span>
<span class="special">}</span>  <span class="comment">// int main()</span>
</pre>
<p>
          There is no useful output from this demonstration program, of course.
        </p>
<p>
          See <a href="../../../../../example/distribution_construction.cpp" target="_top">distribution_construction.cpp</a>
          for full source code.
        </p>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2006-2021 Nikhar Agrawal, Anton Bikineev, Matthew Borland,
      Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno
      Lalande, John Maddock, Evan Miller, Jeremy Murphy, Matthew Pulver, Johan Råde,
      Gautam Sewani, Benjamin Sobotta, Nicholas Thompson, Thijs van den Berg, Daryle
      Walker and Xiaogang Zhang<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="../weg.html"><img src="../../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../weg.html"><img src="../../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../../index.html"><img src="../../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="st_eg.html"><img src="../../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
